import { type Router } from "vue-router";
import { useTagsViewStore } from "@/stores/modules/tagsView";

class RouterUtil {
  //关闭当前页签
  closeTagView(fullPath: string, router: Router, goback?: boolean) {
    const tagsViewStore = useTagsViewStore();
    tagsViewStore.delViewByFullPath(fullPath).then((view: TagView) => {
      if (goback) {
        router.back();
      } else if (view.fullPath) {
        router.push(view.fullPath);
      } else if (view?.name === "Dashboard") {
        router.replace({ path: "/redirect" + view.fullPath });
      } else {
        router.push("/");
      }
    });
  }
}
const routerUtil = new RouterUtil();
export { routerUtil };
